package com.eaoa.query.pub;

import java.util.Iterator;
import java.util.List;

import com.eaoa.base.EABaseQuery;
import com.eaoa.vo.pub.PubDatadictionary;
import com.eaoa.vo.pub.PubDditem;


public class PubDditemQuery extends EABaseQuery{
	public PubDditemQuery() {
		super(PubDditem.class);
	}
	
	
	public void setDdcode(String val){
		setEQCondition("pubDatadictionary.ddcode", val);
	}
	
		public void setFetchParent(){
		setLeftJoinFetchs(" left join fetch this.parent ");
	}
		public void setNOEQItemcode(String  val) {
		super.setNOEQCondition("itemcode", val);
	}
	
	public void setAscOrderBy(String val){
		setASCOrder(val);
	}
	
	public void setNo(Long val) {
		setEQCondition("itemno", val);
	}
	public void setParentno(Long val) {
		setEQCondition("parentno", val);
	}
	public void setItemcode(String val) {
		setEQCondition("itemcode", val);
	}
	public void setLikeItemname(String val) {
		setLIKECondition("itemname", val);
	}
	
	public void setIslock(String islock) {
		setEQCondition("islock", islock);
	}
	
	public void setItemorderASCOrder(){
		setASCOrder("itemorder");
	}
	
	public void setNotInItemcode(String[] val) {
		setNOTINCondition("itemcode", val);	
	}
	
	public static PubDditem loadByNo(Long itemno){
		PubDditemQuery query = new PubDditemQuery(); 
		query.setNo(itemno);
		query.execute();
		List list = query.getResults();
		if(list.size()!=1){
			return null;
		}
		return (PubDditem)list.get(0);		
	}
	
	public static String getConstantByDictionaryAndCode(String ddictionary ,String itemcode){
		PubDatadictionaryQuery dictionaryquery = new  PubDatadictionaryQuery();
		PubDatadictionary dictionary = dictionaryquery.loadByCode(ddictionary);
		Iterator it =  dictionary.getPubDditems().iterator();
		String result = "";
		while(it.hasNext()){
			PubDditem item = (PubDditem)it.next();
			if(item.getItemcode().equals(itemcode)){
				result = item.getItemname();
			}
		}		
		return result;		
	}
	
	public void fetchPubDatadictionary() {
		setLeftJoinFetchs(" inner join fetch this.pubDatadictionary ");
	}
	public void setDdno(Long val){
		setEQCondition("pubDatadictionary.ddno", val);
	}
	public void setDDCode(String val){
		this.setEQCondition("pubDatadictionary.ddcode", val);
	}
	
	public static List getAssetName(Long parentno)
	{
		PubDditemQuery query = new PubDditemQuery(); 
		query.setParentno(parentno);
		query.execute();
		List list = query.getResults();
		
		return list;
	} 
}
